package com.yangff.controller;



import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yangff.anno.LogExecuteTime;
import com.yangff.entity.admin.entity.dto.ListFundDTO;
import com.yangff.entity.product.entity.dto.FinancialproductDTO;
import com.yangff.entity.product.entity.vo.ProductVo;
import com.yangff.entity.vo.ResultVo;
import com.yangff.entity.product.entity.dto.AutoStockDTO;
import com.yangff.service.IProductmanagementService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 存储管理员对理财产品的管理操作记录 前端控制器
 * </p>
 *
 * @author yangff
 * @since 2025-01-15
 */
@LogExecuteTime
@RestController
@RequiredArgsConstructor
@RequestMapping("/productmanagement")
@Slf4j

public class ProductmanagementController{
    private final IProductmanagementService productmanagementService;

    @Cacheable(cacheNames = "product",key = "#code")
    @GetMapping("/{code}")
    public ProductVo getProductByCode(@PathVariable String code) {
        return productmanagementService.getProductByCode(code);
    }



    @GetMapping
    public Page<ProductVo> selectProduct(@PageableDefault Pageable pageable) {
        return productmanagementService.selectProduct(pageable);
    }

    //@CachePut(cacheNames = "product", key = "#financialproductDTO.code")
    @PostMapping
    public ProductVo saveProduct(@RequestBody FinancialproductDTO financialproductDTO)
    {
        return productmanagementService.saveProduct(financialproductDTO);
    }

    @PostMapping("/type")
    public ProductVo saveProductByType(@RequestBody AutoStockDTO autoStockDTO) {
        return productmanagementService.saveProductByType(autoStockDTO);
    }

    //把注册的基金上市，传入初始值和代码
    @PostMapping("/listfund")
    public ResultVo ListFund(@RequestBody ListFundDTO listFundDTO) {
        return productmanagementService.ListFund(listFundDTO.getCode(), listFundDTO.getInitialPrice());
    }

    //将产品退市
    @DeleteMapping("/delistfund/{code}")
    public ResultVo DelistFund(@PathVariable String code) {
        productmanagementService.DelistFund(code);
        return ResultVo.success();
    }

    @DeleteMapping("/{code}")
    public ResultVo deleteProductByCode(@PathVariable String code) {
        productmanagementService.deleteProductByCode(code);
        return ResultVo.success();
    }



}
